package com.bangyu.monitor.modular.system.service;

import com.bangyu.monitor.modular.system.entity.StandDisplayment;
import com.bangyu.monitor.modular.system.entity.OriginalData;
import com.bangyu.monitor.modular.system.entity.RealtimeOriginalDto;
import com.bangyu.monitor.modular.system.mapper.OriginalDataMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther: zhangxue
 * @Date: 19/4/1 13:47
 * @Description:
 */
@Service
@Slf4j
public class OriginalDataService extends ServiceImpl<OriginalDataMapper, OriginalData> {

//    private static final ExecutorService executor = Executors.newFixedThreadPool(5);



    public void insertBatch(List<OriginalData> datas){
        if(CollectionUtils.isNotEmpty(datas)){
            log.info("入库原始数据{}条",datas.size());
            this.baseMapper.batchInsert(datas);
        }
    }

    //异步批量保存
//    public void asynchInsertBatch(List<OriginalData> datas){
//        executor.execute(new Runnable() {
//            @Override public void run() {
//                insertBatch(datas);
//            }
//        });
//    }

    /**
     * 获取前一天的静态标准挠度值
     * 取前一天0-6点的静态原始数据，按照温度分组，用数据最多的那组，取得平均挠度值
     * @param receiveDate
     * @return
     */
    public StandDisplayment getStandBendPreDate(String beamNo,String receiveDate,long endTime){
        List<StandDisplayment> bendValues =  baseMapper.getStaticDisplaymentPreDate(beamNo,receiveDate,endTime);
        if(CollectionUtils.isNotEmpty(bendValues)){
            return bendValues.get(0);
        }
        return null;
    }

    public List<RealtimeOriginalDto> queryByTimeLimit(String beamNo,String receiveDate,long startDate){
        return baseMapper.queryByTimeLimit(beamNo,receiveDate,startDate);
    }

    public void removeByReceiveDate(int receiveDate){
        this.baseMapper.removeByReceiveDate(receiveDate);
    }


}
